package com.gxa.admin.controller;

import com.gxa.common.vo.PageRecv;
import com.gxa.common.vo.R;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.pojo.Contract;
import com.gxa.modules.pojo.LoanSearch;
import com.gxa.modules.service.ContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * @program: microloans_system
 * @description: 合同管理Controller
 * @author: LC
 * @create: 2021-12-28 16:07
 */

@Api(value = "合同管理接口",tags = "（李晨）合同管理接口")
@RestController
@RequestMapping("/contract")
public class ContractController {

    @Autowired(required = false)
    ContractService contractService;


    @ApiOperation(value = "查询合同信息", notes = "用分页的方式查询合同信息", response = R.class)
    @PostMapping("/getContractInfo")
    public ResultVo getContractInfo(@RequestBody PageRecv<LoanSearch> loanSearchPageRecv){
        ResultVo r = contractService.getContractInfo(loanSearchPageRecv);
        return r;
    }


    @ApiOperation(value = "上传文件", notes = "上传多个文件", response = R.class)
    @PostMapping("/uploadFile")
    public ResultVo uploadFile(@RequestBody MultipartFile file){
        ResultVo r=contractService.uploadFile(file);
        return r;
    }



    @ApiOperation(value = "下载合同", notes = "下载合同", response = R.class)
    @GetMapping("/download")
    public void downloadFile(String fileUrl, HttpServletResponse response){
        contractService.downloadFile(fileUrl,response);
    }

    @ApiOperation(value = "预览合同", notes = "预览合同", response = R.class)
    @GetMapping("/preview")
    public void previewFile(String fileUrl, HttpServletResponse response){
        contractService.previewFile(fileUrl,response);
    }


    @ApiOperation(value = "添加合同", notes = "添加合同", response = R.class)
    @PostMapping("/addContract")
    public ResultVo addContract(@RequestBody Contract contract){
        ResultVo r=contractService.addContract(contract);
        return r;
    }




}